﻿using System;
using System.Collections.Generic;
using System.Text;
using Gencode.Common.Errorhandling;

namespace Gencode.PrsCommon.App
{
    public enum PlanValueType { Dienst, Color, None };
    public class PlanUtil
    {
        static PlanValueType valueType = PlanValueType.None;
        public static PlanValueType ValueType
        {
            get
            {
                return valueType;
            }
            set
            {
                valueType = value;
            }
        }

		static bool _useDienst = false;
		/// <summary>
		/// Use Dienst value on grid click
		/// </summary>
		public static bool UseDienst
		{
			get
			{
				return _useDienst;
			}
			set
			{
				_useDienst = value;
			}
		}

        /// <summary>
        /// Gets the name of the selected Dienst. To set new name set the DienstID value.
        /// </summary>
		public static string SelectedDienst
		{
			get;
			private set;
		}

		static int _dienstARGB = 0;
		/// <summary>
		/// Gets color of the selected Dienst. To set new color set the DienstID value.
		/// </summary>
		public static int SelectedDienstARGB
		{
			get
			{
				return _dienstARGB;
			}
			private set
			{
				_dienstARGB = value;
			}
		}

        static int dienstID;
        public static int SelectedDienstID
        {
            get
            {
                return dienstID;
            }
            set
            {
                if (value == 0)
                {
                    dienstID = 0;
                    SelectedDienst = string.Empty;
					SelectedDienstARGB = 0;
                }
                else
                {
                    dienstID = value;
                    if (Mandant == null || Mandant == string.Empty)
                        throw new UserException("Missing Mandant in PlanUtil.Mandant");

                    System.Data.DataView dv = Gencode.PrsCommon.Data.Dienst.DienstData.GetDienste(Mandant, dienstID);
                    SelectedDienst = dv[0].Row["Name"].ToString();

					SelectedDienstARGB = 0;
					try
					{
						SelectedDienstARGB = int.Parse(dv[0].Row["RGB"].ToString());
					}
					catch { }

                    dv.Dispose();
                }
            }
        }

        public static string Mandant
        {
            get;
            set;
        }

		static bool _useColor = false;
		/// <summary>
		/// Use color on grid click
		/// </summary>
		public static bool UseColor
		{
			get
			{
				return _useColor;
			}
			set
			{
				_useColor = value;
			}
		}

        static int argb;
        public static int ARGB
        {
            get
            {
                return argb;
            }
            set
            {
                //if (value == -1)
                //    argb = 0;
                //else
                argb = value;
            }
        }
    }
}
